package proxy;

import dto.BigStar;
import dto.Star;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class StarProxy {
    public static Star createStarProxy(BigStar bigStar){
        Star starProxy = (Star) Proxy.newProxyInstance(StarProxy.class.getClassLoader(),
                new Class[]{Star.class}, new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        if (method.getName().equals("sing")) {
                            System.out.println("sing");
                        }else if (method.getName().equals("dance")){
                            System.out.println("dance");
                        }
                        return method.invoke(bigStar,args);
                    }
                });
        
        return starProxy;
                
    }
}
